package com.test.lock;

import java.util.concurrent.CountDownLatch;

public class CountDownLatchApp {

	public static void main(String[] args) throws InterruptedException {
		CountDownLatch lock = new CountDownLatch(1);
		for(int i=0;i<5;i++) {
			new Thread(()->{
				try {
					System.out.println("开始等待");
					lock.await();
					System.out.println("执行任务");
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}) .start();
		}
		try {
			Thread.sleep(5000);
			System.out.println("主线程通知开始执行任务");
			lock.countDown();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}
